.TH std::filesystem::path::operator= 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::filesystem::path::operator= \- std::filesystem::path::operator=

.SH Synopsis
   path& operator=( const path& p );        \fB(1)\fP \fI(since C++17)\fP
   path& operator=( path&& p ) noexcept;    \fB(2)\fP \fI(since C++17)\fP
   path& operator=( string_type&& source ); \fB(3)\fP \fI(since C++17)\fP
   template< class Source >                 \fB(4)\fP \fI(since C++17)\fP
   path& operator=( const Source& source );

   1) Replaces the contents of *this with a pathname whose both native and generic
   format representations equal those of p.
   2) Replaces the contents of *this with a pathname whose both native and generic
   format representations equal those of p, possibly using move semantics: p is left in
   a valid, but unspecified state.
   3) Replaces the contents of *this with a new path value constructed from
   detected-format source, which is left in valid, but unspecified state. Equivalent to
   assign(std::move(source)).
   4) Replaces the contents of *this with a new path value constructed from
   detected-format source as if by overload \fB(4)\fP of the path constructor. Equivalent to
   assign(source).

   \fB(4)\fP participates in overload resolution only if Source and path are not the same
   type, and either:

     * Source is a specialization of std::basic_string or std::basic_string_view, or
     * std::iterator_traits<std::decay_t<Source>>::value_type is valid and denotes a
       possibly const-qualified encoding character type (char,
       char8_t,
       \fI(since C++20)\fPchar16_t, char32_t, or wchar_t).

.SH Parameters

   p      - a path to assign
            a std::basic_string, std::basic_string_view, pointer to a null-terminated
            character/wide character string, or an input iterator that points to a
   source - null-terminated character/wide character sequence. The character type must
            be one of char,
            char8_t,
            \fI(since C++20)\fPchar16_t, char32_t, wchar_t

.SH Return value

   *this

.SH Example


// Run this code

 #include <filesystem>
 namespace fs = std::filesystem;

 int main()
 {
     fs::path p = "C:/users/abcdef/AppData/Local";
     p = p / "Temp"; // move assignment
     const wchar_t* wstr = L"D:/猫.txt";
     p = wstr; // assignment from a source
 }

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

      DR    Applied to              Behavior as published              Correct behavior
   LWG 3244 C++17      constraint that Source cannot be path was       added
                       missing

.SH See also

   assign        assigns contents
                 \fI(public member function)\fP
   constructor   constructs a path
                 \fI(public member function)\fP
